package team.knowers.qzh.qzhgrame.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import team.knowers.qzh.qzhgrame.common.convention.result.Result;
import team.knowers.qzh.qzhgrame.common.convention.result.Results;
import team.knowers.qzh.qzhgrame.dto.req.UserLoginReqDTO;
import team.knowers.qzh.qzhgrame.dto.resp.UserLoginRespDTO;
import team.knowers.qzh.qzhgrame.dto.resp.UserMessageRespDTO;
import team.knowers.qzh.qzhgrame.service.UserGrameService;


/**
 * @author wutai
 */
@RequiredArgsConstructor
@RestController
public class UserGrameController {
    private final UserGrameService usergrameService;

    /**
     * 用户登录
     */
    @PostMapping("/api/qzh-server/admin/v1/grame/login")
    public Result<UserLoginRespDTO> login(@RequestBody UserLoginReqDTO requestParam) {
        return Results.success(usergrameService.login(requestParam));
    }

    /**
     * 用户退出登录
     */
    @DeleteMapping("/api/qzh-server/admin/v1/grame/logout")
    public Result<Boolean> logout(@RequestParam("username") String username, @RequestParam("token") String token) {
        return Results.success(usergrameService.logout(username, token));
    }

    /**
     * 用户是否已登录
     */
    @GetMapping("/api/qzh-server/admin/v1/grame/isUserLogin")
    public Result<Boolean> isUserLogin(@RequestParam("username") String username, @RequestParam("token") String token) {
        return Results.success(usergrameService.isUserLogin(username, token));
    }

    /**
     * 封禁用户
     */
    @PutMapping("/api/qzh-server/admin/v1/grame/ban/{username}")
    public Result<String> ban(@PathVariable("username") String username) {
        return Results.success(usergrameService.ban(username));
    }

    /**
     * 用户解封
     */
    @PutMapping("/api/qzh-server/admin/v1/grame/relieve/{username}")
    public Result<String> relieve(@PathVariable("username") String username) {
        return Results.success(usergrameService.relieve(username));
    }
    /**
     * 查询创作者创作
     */
    @GetMapping("/api/qzh-server/admin/v1/grame/show/{username}")
    public Result<UserMessageRespDTO> showUser(@PathVariable("username")String username){
        return Results.success(usergrameService.showUser(username));
    }

}
